#!/bin/sh
# script courtesy of Sergio Vicari <sercari@esdebian.org>

DICTD=/usr/sbin/dictd

# DICTD_OPTIONS="-put -command_line -options -for -dictd -here"
DICTD_OPTIONS=""


PIDFILE=/var/run/dictd.pid

start() {

    if [ -x $DICTD ]; then
        echo "dictd starting."
        $DICTD $DICTD_OPTIONS
    else
        echo "rc.dictd: cannot find $DICTD or it's not executable"
    fi
}

stop() {
  if [ -e "$PIDFILE" ]; then
    echo "Stopping the dictd server."
    pid=$(cat $PIDFILE)
    kill $pid 1> /dev/null 2> /dev/null
    # Just in case:
    killall dictd 1> /dev/null 2> /dev/null
    rm -f $PIDFILE
  fi
}
reload() {
  echo "Reloading dictd."
  if [ -e "$PIDFILE" ]; then
    pid=$(cat $PIDFILE)
    kill -HUP $pid
  else
    killall -HUP dictd
  fi
}

status() {
  if [ -e /var/run/dictd.pid ]; then
    echo "the dictd server is running."
  else
    echo "dictd server is stopped."
  fi
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  reload)
    reload
    ;;
  status)
    status
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|reload|status}"
    ;;
esac
